
	/**
	 * 
	 */
	function Wave() {
		
		/** The current dimensions of the screen (updated on resize) */
		var WIDTH = window.innerWidth;
		var HEIGHT = window.innerHeight;
		
		/** Wave settings */
		var DENSITY = .75;
		var FRICTION = 1.14;
		var MOUSE_PULL = 0.09; // The strength at which the mouse pulls particles within the AOE
		var AOE = 200; // Area of effect for mouse pull
		var DETAIL = Math.round( WIDTH / 60 ); // The number of particles used to build up the wave
		var WATER_DENSITY = 1.07;
		var AIR_DENSITY = 1.02;
		var TWITCH_INTERVAL = 2000; // The interval between random impulses being inserted into the wave to keep it moving
		
		/** Twitter interaction settings */
		var TWITTER_QUERY = 'water'; // The search term for tweets
		var TWEETS_PER_PAGE = 20; // The number of tweets that will be fetched per server call
		var TWEETS_FREQUENCY = 400; // Milliseconds between tweet bubbles being added to the wave
		
		/** Bubble settings */
		var MAX_BUBBLES = 60; // The maximum number of bubbles visible before FIFO is applied
		var BIG_BUBBLE_DISSOLVE = 20; // How many particles a bubble dissolves into when being clicked
		var SMALL_BUBBLE_DISSOLVE = 6;
		
		/** Couple of counters to keep track of the Twitter interaction */
		var twitterPolls = 1; // Counts how many times data has been fetched from twitter
		var twitterRetries = 0; // Counts how many times we fail to retrieve results from twitter
		var twitterMaxId = 0; // The ID of the oldest tweet that's been downloaded
		
		var mouseIsDown, isDownloadingTweets = false;
		var ms = {x:0, y:0}; // Mouse speed
		var mp = {x:0, y:0}; // Mouse position
		
		var canvas, context, particles, bubbles, tweets;
		
		var timeUpdateInterval, tweetUpdateInterval, twitchInterval;
		
		/**
		 * Constructor.
		 */
		this.Initialize = function( canvasID ) {
			canvas = document.getElementById( canvasID );
			
			if (canvas && canvas.getContext) {
				context = canvas.getContext('2d');
				
				particles = [];
				tweets = [];
				bubbles = [];
				
				$("body").append('<div id="tweet"></div>');
				
				// Generate our wave particles
				for( var i = 0; i < DETAIL+1; i++ ) {
					particles.push( { 
						x: WIDTH / (DETAIL-4) * (i-2), // Pad by two particles on each side
						y: HEIGHT*.5,
						original: {x: 0, y: HEIGHT * .5},
						velocity: {x: 0, y: Math.random()*3}, // Random for some initial movement in the wave
						force: {x: 0, y: 0},
						mass: 10
					} );
				}
				
				$(canvas).mousemove(MouseMove);
				$(canvas).mousedown(MouseDown);
				$(canvas).mouseup(MouseUp);
				$(window).resize(ResizeCanvas);
				
				timeUpdateInterval = setInterval( TimeUpdate, 40 );
				tweetUpdateInterval = setInterval( CreateBubble, TWEETS_FREQUENCY );
				twitchInterval = setInterval( Twitch, TWITCH_INTERVAL );
				DownloadTweets();
				CreateBubble();
				ResizeCanvas();
			}
		};
		
		/**
		 * Stops downloading and showing tweets.
		 */
		function Terminate( message ) {
			clearInterval( tweetUpdateInterval );
			isDownloadingTweets = true;
			
			alert( message );
		}
		
		/**
		 * Gets the next tweet in queue. If there are
		 * less than five tweets remaining, download a
		 * new batch.
		 */
		function GetTweet() {
			if( tweets.length < 5 && !isDownloadingTweets ) {
				DownloadTweets();
			}
			
			if (tweets.length > 0) {
				return tweets.shift();
			}
		}
		
		/**
		 * 
		 */
		function DownloadTweets() {
			isDownloadingTweets = true;
			document.gete
			if( twitterPolls ++ > 20 ) {
				Terminate( "That's it. No more tweets for you." );
			}
			
			$.post("search.php", {query: TWITTER_QUERY, max_id: twitterMaxId, rpp: TWEETS_PER_PAGE}, function(xml){
				
				if( !$('entry',xml) || $('entry',xml).length == 0 ) {
					if (twitterRetries++ > 3) {
						Terminate("Oops, Twitter doesn't want to serve us at the moment.");
					}
				}
				
				$('entry',xml).each(function(i){
					var tweet = {};
					tweet.title = $(this).find("title").text();   
					tweet.content = $(this).find("content").text();   
					tweet.published = $(this).find("published").text();   
					tweet.link = $(this).find("link").text();   
					tweet.authorURI = $(this).find("uri").text();
					tweet.author = $(this).find("name").text();
					tweet.author = "@" + tweet.author.slice(0, tweet.author.indexOf(" "));
					tweet.id = $(this).find("id").text();
					tweet.id = tweet.id.slice( tweet.id.lastIndexOf(":") + 1 );
					
					if( i == $('entry',xml).length - 1 ) {
						twitterMaxId = parseInt( tweet.id ) - 1;
					}
					tweets.push( tweet );
				});
				
				isDownloadingTweets = false;
				
			});
		}
		
		/**
		 * 
		 */
		function ShowTweet( bubbleIndex ) {
			var tweet = GetTweet();
			var tweetMarkup = tweet.content + "<br/><p class='author'>by: <a href='"+tweet.authorURI+"'>" + tweet.author + "</p>";
			$("#tweet").hide().html( tweetMarkup ).fadeIn();
			
			DissolveBubble( bubbleIndex );
		}
		
		/**
		 * Inserts a random impulse to keep the wave moving.
		 * Impulses are only inserted if the mouse is not making
		 * quick movements.
		 */
		function Twitch() {
			if( ms.x < 6 || ms.y < 6 ) {
				var forceRange = 5; // -value to +value
				InsertImpulse( Math.random() * WIDTH, (Math.random()*(forceRange*2)-forceRange ) );
			}
		}
		
		/**
		 * Inserts an impulse in the wave at a specific position.
		 * 
		 * @param positionX the x coordinate where the impulse
		 * should be inserted
		 * @param forceY the force to insert
		 */
		function InsertImpulse( positionX, forceY ) {
			var particle = particles[Math.round( positionX / WIDTH * particles.length )];
			
			if( particle ) {
				particle.force.y += forceY;
			}
		}
		
		/**
		 * 
		 */
		function TimeUpdate(e) {
			
			var gradientFill = context.createLinearGradient(WIDTH*.5,HEIGHT*.2,WIDTH*.5,HEIGHT);
			gradientFill.addColorStop(0,'#00AABB');
			gradientFill.addColorStop(1,'rgba(0,200,250,0)');
			
			context.clearRect(0, 0, WIDTH, HEIGHT);
			context.fillStyle = gradientFill;
			context.beginPath();
			context.moveTo(particles[0].x, particles[0].y);
			
			var len = particles.length;
			var i;
			
			var current, previous, next;
			
			for( i = 0; i < len; i++ ) {
				current = particles[i];
				previous = particles[i-1];
				next = particles[i+1];
				
				if (previous && next) {
					
					var forceY = 0;
					
					forceY += -DENSITY * ( previous.y - current.y );
					forceY += DENSITY * ( current.y - next.y );
					forceY += DENSITY/15 * ( current.y - current.original.y );
					
					current.velocity.y += - ( forceY / current.mass ) + current.force.y;
					current.velocity.y /= FRICTION;
					current.force.y /= FRICTION;
					current.y += current.velocity.y;
					
					var distance = DistanceBetween( mp, current );
					
					if( distance < AOE ) {
						var distance = DistanceBetween( mp, {x:current.original.x, y:current.original.y} );
						
						ms.x = ms.x * .98;
						ms.y = ms.y * .98;
						
						current.force.y += (MOUSE_PULL * ( 1 - (distance / AOE) )) * ms.y;
					}
					
					// cx, cy, ax, ay
					context.quadraticCurveTo(previous.x, previous.y, previous.x + (current.x - previous.x) / 2, previous.y + (current.y - previous.y) / 2);
				}
				
			}
			
			context.lineTo(particles[particles.length-1].x, particles[particles.length-1].y);
			context.lineTo(WIDTH, HEIGHT);
			context.lineTo(0, HEIGHT);
			context.lineTo(particles[0].x, particles[0].y);
			
			context.fill();
			
			len = bubbles.length;
			
			context.fillStyle = "#rgba(0,200,255,0)";
			context.beginPath();
			
			var b, p, d;
			
			for (i = 0; i < len; i++) {
				var b = bubbles[i];
				var p = GetClosestParticle( b );
				var d = DistanceBetween( mp, b );
				
				b.velocity.y /= ( b.y > p.y ) ? WATER_DENSITY : AIR_DENSITY;
				b.velocity.y += ( p.y > b.y ) ? 1/b.mass : -((b.y-p.y)*0.01)/b.mass;
				b.y += b.velocity.y;
				
				if( b.x > WIDTH - b.currentSize ) b.velocity.x = -b.velocity.x;
				if( b.x < b.currentSize ) b.velocity.x = Math.abs(b.velocity.x);
				
				b.velocity.x /= 1.04;
				b.velocity.x = b.velocity.x < 0 ? Math.min( b.velocity.x, -.8/b.mass ) : Math.max( b.velocity.x, .8/b.mass )
				b.x += b.velocity.x;
				
				if( d < AOE ) {
					// The bubble is within the AOE, apply horizontal mouse pull relative to distance
					//b.velocity.x += MOUSE_PULL * ( ( AOE - d ) / AOE * b.mass ) * ms.x;
				}
				
				if( b.dissolved == false ) {
					context.moveTo(b.x,b.y);
					context.arc(b.x,b.y,b.currentSize,0,Math.PI*2,true);
				}
				else {
					b.velocity.x /= 1.15;
					b.velocity.y /= 1.05;
					
					while( b.children.length < b.dissolveSize ) {
						b.children.push( { x:0, y:0, size: Math.random()*b.dissolveSize, velocity: { x: (Math.random()*20)-10, y: -(Math.random()*10) } } );
					}
					
					for( var j = 0; j < b.children.length; j++ ) {
						var c = b.children[j];
						c.x += c.velocity.x;
						c.y += c.velocity.y;
						c.velocity.x /= 1.1;
						c.velocity.y += 0.4;
						c.size /= 1.1;
						
						context.moveTo(b.x+c.x,b.y+c.y); // needed in ff
						context.arc(b.x+c.x,b.y+c.y,c.size,0,Math.PI*2,true);
					}
					
				}
				
			}
			
			context.fill();
		}
		
		/**
		 * 
		 */
		function GetClosestParticle(point){
			var closestIndex = 0;
			var closestDistance = 1000;
			
			var len = particles.length;
			
			for( var i = 0; i < len; i++ ) {
				var thisDistance = DistanceBetween( particles[i], point );
				
				if( thisDistance < closestDistance ) {
					closestDistance = thisDistance;
					closestIndex = i;
				}
				
			}
			
			return particles[closestIndex];
		}
		
		/**
		 * 
		 */
		function CreateBubble() {
			if( bubbles.length > MAX_BUBBLES ) {
				var i = 0;
				
				if( bubbles[i].dissolved ) {
					// Find a bubble thats not already on its way to dissolving
					for( ; i < bubbles.length; i++ ) {
						if( bubbles[i].dissolved == false ) {
							bubbles[i].dissolveSize = SMALL_BUBBLE_DISSOLVE;
							DissolveBubble( i );
							break;
						}
					}
				}
				else {
					DissolveBubble( i );
				}
				
			}
			
			var minSize = 15;
			var maxSize = 30;
			var size = minSize + Math.random() * ( maxSize - minSize );
			var catapult = 30;
			
			var b = {
				x: maxSize + ( Math.random() * ( WIDTH - maxSize ) ),
				y: HEIGHT - maxSize,
				velocity: {x: (Math.random()*catapult)-catapult/2,y: 0},
				size: size,
				mass: (size / maxSize)+1,
				dissolved: false,
				dissolveSize: BIG_BUBBLE_DISSOLVE,
				children: []
			};
			
			b.currentSize = b.size;
			
			bubbles.push(b);
		}
		function DissolveBubble( index ) {
			var b = bubbles[index];
			
			if( b.dissolved == false ) {
				b.dissolved = true;
				
				setTimeout( function() {
					for( var i = 0; i < bubbles.length; i++ ) {
						if( bubbles[i] == b ) {
							bubbles.splice(i,1);
							break;
						}
					}
					
				}, 2000 );
			}
		}
		
		/**
		 * 
		 */
		function MouseMove(e) {
			ms.x = Math.max( Math.min( e.layerX - mp.x, 40 ), -40 );
			ms.y = Math.max( Math.min( e.layerY - mp.y, 40 ), -40 );
			
			mp.x = e.layerX;
			mp.y = e.layerY;
			
		}
		function MouseDown(e) {
			mouseIsDown = true;
			
			var len = bubbles.length;
			
			var closestIndex = 0;
			var closestDistance = 1000;
			
			for( var i = 0; i < len; i++ ) {
				var thisDistance = DistanceBetween( bubbles[i], mp );
				
				if( thisDistance < closestDistance ) {
					closestDistance = thisDistance;
					closestIndex = i;
				}
				
			}
			
			if (bubbles.length && closestDistance < 150) {
				ShowTweet( closestIndex );
			}
		}
		function MouseUp(e) {
			mouseIsDown = false;
		}
		
		/**
		 * 
		 */
		function ResizeCanvas(e) {
			WIDTH = window.innerWidth;
			HEIGHT = window.innerHeight;
			
			canvas.width = WIDTH;
			canvas.height = HEIGHT;
			
			$("#tweet").css( "top", HEIGHT * .7 );
			
			for( var i = 0; i < DETAIL+1; i++ ) {
				particles[i].x = WIDTH / (DETAIL-4) * (i-2);
				particles[i].y = HEIGHT*.5;
				
				particles[i].original.x = particles[i].x;
				particles[i].original.y = particles[i].y;
			}
		}
		
		/**
		 * 
		 */
		function DistanceBetween(p1,p2) {
			var dx = p2.x-p1.x;
			var dy = p2.y-p1.y;
			return Math.sqrt(dx*dx + dy*dy);
		}
		
	}
	
	var wave = new Wave();
	wave.Initialize( 'world' );




    /**
 *
 * OpenOdyssey
 * by Michal Budzynski for MozillaGameOn 2010
 * http://michalbe.blogspot.com
 * http://twitter.com/michalbe
 *
 */

    (function() {
        Z_CHARACTERS = 20;
        Z_GUI = 99999;
        PAUSED = 1;
        LEVELS = [];
        LEVELS.push({board:"lvl1.png",background:"lvl1.png",enemies:["soldier1","soldier2","soldier3"],obstacles:["palm","bush","column"],nrOfEnemies:3,nrOfObstacles:4});
        LEVELS.push({board:"lvl2.png",background:"lvl2.png",enemies:["cyclop1","cyclop2","cyclop3"],obstacles:["stone","stone2"],nrOfEnemies:3,nrOfObstacles:5});
        LEVELS.push({board:"lvl3.png",background:"lvl3.png",enemies:["hades","hades2","hades3","hades4"],obstacles:["stone","column"],nrOfEnemies:6, nrOfObstacles:2});
        LEVELS.push({board:"lvl4.png",background:"lvl4.png",enemies:["shepherd2","shepherd","shepherd3"],obstacles:["stone","cactus"],nrOfEnemies:4,nrOfObstacles:7});
        LEVELS.push({board:"lvl5.png",background:"lvl1.png",enemies:["shepherd2","shepherd","shepherd3","cyclop1","cyclop2","cyclop3","soldier1","soldier2","soldier3","hades","hades2","hades3","hades4"],obstacles:["stone","cactus","bush","stone2","palm"],nrOfEnemies:5,nrOfObstacles:3});
        StructuresWithShadow = {playerConf:{filename:"odys", width:80,height:90,frames:3,animations:1,animationSpeed:5,shadowDistance:80,collisionZone:{top:50,right:23,bottom:0,left:7}},palm:{filename:"obstacles/palmTree",width:82,height:100,frames:0,animations:0,animationSpeed:0,shadowDistance:82,collisionZone:{top:56,right:31,bottom:0,left:31}},cactus:{filename:"obstacles/cactus",width:101,height:120,frames:0,animations:0,animationSpeed:0,shadowDistance:100,collisionZone:{top:85,right:0,bottom:0,left:0}},stone:{filename:"obstacles/stone",width:89,height:80, frames:0,animations:0,animationSpeed:0,shadowDistance:50,collisionZone:{top:40,right:0,bottom:0,left:0}},stone2:{filename:"obstacles/stone2",width:80,height:170,frames:0,animations:0,animationSpeed:0,shadowDistance:120,collisionZone:{top:100,right:0,bottom:0,left:0}},column:{filename:"obstacles/column",width:67,height:120,frames:0,animations:0,animationSpeed:0,shadowDistance:55,collisionZone:{top:55,right:0,bottom:0,left:0}},bush:{filename:"obstacles/bush",width:43,height:40,frames:0,animations:0, animationSpeed:0,shadowDistance:20},spearConf:{filename:"dzida",width:10,height:60,frames:1,animations:0,animationSpeed:4,shadowDistance:70}};
        var F = function(c, i, q) {
            var e = this;
            e.posX = i || 0;
            e.posY = q || 0;
            e.shadowDistance = c.shadowDistance;
            e.conf = c;
            e.character = new t.sprite("images/" + c.filename + ".png", c.width, c.height, c.frames, c.animations);
            e.character.setPosition(e.posX, e.posY, Z_CHARACTERS);
            e.character.setAnimationSpeed(c.animationSpeed);
            e.character.setCurrentAnimation(0);
            e.shadow = new t.sprite("images/" + (c.shadowFile || c.filename + "_shadow") + ".png", c.width, c.height, c.frames, 0);
            e.shadow.setPosition(e.posX, e.posY + e.shadowDistance, 10);
            e.shadow.setAnimationSpeed(c.animationSpeed);
            e.shadow.setCurrentAnimation(0);
            e.setPosition = function(f, v) {
                e.character.setPosition(f, v, v + e.character.height());
                e.shadow.setPosition(f, v + e.shadowDistance);
                e.posX = f;
                e.posY = v
            };
            e.switchSprite = function(f, v, n) {
                e.posX = v || 0;
                e.posY = n || 0;
                e.shadowDistance = f.shadowDistance;
                e.conf = f;
                e.character.switchSprite("images/" + f.filename + ".png", f.width, f.height, f.frames, f.animations);
                e.character.setPosition(e.posX, e.posY, Z_CHARACTERS);
                e.character.setAnimationSpeed(f.animationSpeed);
                e.character.setCurrentAnimation(0);
                e.shadow.switchSprite("images/" + (f.shadowFile || f.filename + "_shadow") + ".png", f.width, f.height, f.frames, 0);
                e.shadow.setPosition(e.posX, e.posY + e.shadowDistance, 10);
                e.shadow.setAnimationSpeed(f.animationSpeed);
                e.shadow.setCurrentAnimation(0);
                f.collisionZone && e.character.setCollisionZone(f.collisionZone.top, f.collisionZone.right, f.collisionZone.bottom, f.collisionZone.left)
            };
            e.clearHits = function() {
                e.character.clearHits()
            };
            c.collisionZone && e.character.setCollisionZone(c.collisionZone.top, c.collisionZone.right, c.collisionZone.bottom, c.collisionZone.left);
            return e
        },u = [],S = function(c) {
            var i = LEVELS[z].obstacles,q = -200,e = ~~(Math.random() * 600);
            i = StructuresWithShadow[i[~~(Math.random() * i.length)]];
            if (c == null) {
                c = u.length;
                q = c * 200;
                u[c] = new F(i, e, q)
            } else {
                u[c].switchSprite(i, e, q);
                u[c].clearHits()
            }
            u[c].character.onHit(h.character, function() {
                R(h, u[c])
            })
        },I = 0;
        EnemiesConfig = {shepherd:{filename:"enemies/shepherd",width:68,height:90,frames:3,animations:1,animationSpeed:4,shadowDistance:80,speed:5,move:function() {
        }},shepherd2:{filename:"enemies/shepherd2",width:68,height:90,frames:3,animations:1,animationSpeed:4,shadowDistance:80,speed:4,shadowFile:"enemies/shepherd_shadow"},shepherd3:{filename:"enemies/shepherd3",width:68,height:90,frames:3,animations:1,animationSpeed:4,shadowDistance:80,speed:6,shadowFile:"enemies/shepherd_shadow",points:3},soldier1:{filename:"enemies/soldier", width:57,height:80,frames:3,animations:1,animationSpeed:4,shadowDistance:70,speed:5,points:2},soldier2:{filename:"enemies/soldier2",width:57,height:80,frames:3,animations:1,animationSpeed:4,shadowDistance:70,speed:6,shadowFile:"enemies/soldier_shadow",points:3},soldier3:{filename:"enemies/soldier3",width:57,height:80,frames:3,animations:1,animationSpeed:4,shadowDistance:70,speed:7,shadowFile:"enemies/soldier_shadow",points:4},cyclop1:{filename:"enemies/cyclop",width:108,height:140,frames:3,animations:1, animationSpeed:4,shadowDistance:130,speed:5,points:2},cyclop2:{filename:"enemies/cyclop2",width:108,height:140,frames:3,animations:1,animationSpeed:4,shadowDistance:130,speed:6,shadowFile:"enemies/cyclop_shadow",points:3},cyclop3:{filename:"enemies/cyclop3",width:108,height:140,frames:3,animations:1,animationSpeed:4,shadowDistance:130,speed:7,shadowFile:"enemies/cyclop_shadow",points:4},hades:{filename:"enemies/hades",width:68,height:102,frames:3,animations:1,animationSpeed:4,shadowDistance:90,speed:4, points:2},hades2:{filename:"enemies/hades2",width:68,height:102,frames:3,animations:1,animationSpeed:4,shadowDistance:90,speed:6,shadowFile:"enemies/hades_shadow",points:1},hades3:{filename:"enemies/hades3",width:68,height:102,frames:3,animations:1,animationSpeed:4,shadowDistance:90,speed:5,shadowFile:"enemies/hades_shadow",points:2},hades4:{filename:"enemies/hades4",width:68,height:102,frames:3,animations:1,animationSpeed:4,shadowDistance:90,speed:6,shadowFile:"enemies/hades_shadow",points:1}};
        var r = [],J = function(c) {
            I++;
            var i = LEVELS[z].enemies,q = -200,e = ~~(Math.random() * 600 - 50);
            i = EnemiesConfig[i[~~(Math.random() * i.length)]];
            if (c == null) {
                c = r.length;
                q = 50 - c * 200;
                r[c] = new F(i, e, q)
            } else {
                r[c].switchSprite(i, e, q);
                r[c].clearHits()
            }
            for (q = u.length; q--;)r[c].character.onHit(u[q].character, function() {
                R(r[c], u[0])
            });
            r[c].character.onHit(h.character, function() {
                if (h.character.getCurrentAnimation() === 0 && r[c].character.getCurrentAnimation() === 0) {
                    h.character.setCurrentAnimation(1);
                    setTimeout(function() {
                        h.character.setCurrentAnimation(0)
                    }, 1E3);
                    setTimeout(aa, 0)
                }
            });
            r[c].character.onHit(A.character, function() {
                h.shoot = 0;
                A.setPosition(-200, -200);
                r[c].character.setCurrentAnimation(1);
                r[c].conf.points ? C += r[c].conf.points : C++;
                T(C);
                setTimeout(function() {
                    J(c)
                }, 250);
                if (I > 120) {
                    localStorage.odysseyPoints = C;
                    localStorage.odysseyLevel = z += 1;
                    if (localStorage.odysseyLevel > 4) {
                        localStorage.odysseyPoints = 0;
                        localStorage.odysseyLevel = 0;
                        var f = window.location.href.split("/");
                        f.pop();
                        f.push("win.html");
                        window.location = f.join("/");
                        console.log("aa")
                    } else window.location = window.location.href
                }
            })
        },z = 0,C = 0;
        if (localStorage.odysseyLevel)z = parseInt(localStorage.odysseyLevel, 10);
        if (localStorage.odysseyPoints)C = parseInt(localStorage.odysseyPoints, 10);
        var t = new function(c, i, q) {
            var e = true,f = [],v = q ? document.getElementById(q) : document.body,n,o,D = c || 400,w = i || 300,G = [],K = 1E3 / 33,U,L = new Date,H = false,E = {},x = [],V = [];
            if (!Array.indexOf)Array.prototype.indexOf = function(g) {
                for (var p = 0; p < this.length; p++)if (this[p] == g)return p;
                return-1
            };
            var M = 0,W = 0,X = function() {
                if (H)L = new Date;
                n.style.width = n.width = D;
                n.style.height = n.height = w;
                v.appendChild(n)
            },ba = function() {
                n = document.createElement("canvas");
                X();
                o = n.getContext("2d");
                f.sort(function(g, p) {
                    return g.zOrder - p.zOrder
                })
            },Y = function() {
                if (e) {
                    o.fillStyle = "#fff";
                    o.beginPath();
                    o.rect(0, 0, D, w);
                    o.closePath();
                    o.fill()
                }
                for (var g = f.length; g--;)f[g].draw();
                for (g = G.length; g--;)G[g]();
                if (H) {
                    g = new Date;
                    if (Math.ceil(g.getTime() - L.getTime()) >= 1E3) {
                        W = M;
                        M = 0;
                        L = g
                    }
                    g = W + "/" + 1 / (K / 1E3);
                    if (e) {
                        o.fillStyle = "#fff";
                        o.font = "10px Arial";
                        o.fillText("FPS: " + g, 3, 11);
                        o.fillStyle = "Black";
                        o.font = "10px Arial";
                        o.fillText("FPS: " + g, 2, 10)
                    } else if (E.fpsDiv)E.fpsDiv.innerHTML = "FPS: " + g;
                    M++
                }
                U = setTimeout(Y, K)
            },ca = function() {
                for (var g = x.length,p,j,d,s,a,b,k,m,B; g--;) {
                    j = x[g];
                    s = j.posY + j.collisionZone.top;
                    a = j.posY + j.height - j.collisionZone.bottom;
                    b = j.posX + j.collisionZone.left;
                    j = j.posX + j.width - j.collisionZone.right;
                    for (p in x[g].hitEvents) {
                        d = V[p];
                        k = d.posY + d.collisionZone.top;
                        m = d.posY + d.height - d.collisionZone.bottom;
                        B = d.posX + d.collisionZone.left;
                        d = d.posX + d.width - d.collisionZone.right;
                        s > m || a < k || b > d || j < B || x[g].hitEvents[p]()
                    }
                }
            };
            return{showFps:function() {
                H = true
            },detectCanvas:function() {
                document.createElement("canvas").getContext || (e = false)
            },setMaxFps:function(g) {
                K = 1E3 / g
            },addCss:function(g) {
                n.className = g
            },init:function() {
                if (e)ba(); else {
                    n = document.createElement("div");
                    n.style.position = "absolute";
                    n.style.overflow = "hidden";
                    X();
                    if (H) {
                        var g = document.createElement("style");
                        g.setAttribute("type", "text/css");
                        if (g.styleSheet)g.styleSheet.cssText = "#fpsDiv {position:absolute;z-index:999;font-weight:bold;top:0;left:0;padding:5px;}"; else g.innerHTML = "#fpsDiv {position:absolute;z-index:999;font-weight:bold;top:0;left:0;padding:5px;}";
                        document.getElementsByTagName("head")[0].appendChild(g);
                        E.fpsDiv = document.createElement("div");
                        E.fpsDiv.id = "fpsDiv";
                        n.appendChild(E.fpsDiv)
                    }
                }
            },start:Y,stop:function() {
                clearTimeout(U)
            },canvas:function() {
                return n
            },enableCanvas:function() {
                e = true
            },disableCanvas:function() {
                e = false
            },enableCollisions:function() {
                G.push(ca)
            },sprite:function(g, p, j, d, s) {
                var a = {};
                a.id = f.length;
                a.image = new Image;
                a.image.src = g;
                a.speed = 1;
                a.width = p;
                a.initialWidth = p;
                a.height = j;
                a.initialHeight = j;
                a.frames = d;
                a.animations = s;
                a.colllides = false;
                a.hitEvents = {};
                a.actualFrame = 0;
                a.actualAnimation = 0;
                a.animationSpeed = 1;
                a.animationInterval = 0;
                a.posX = 0;
                a.posY = 0;
                a.zOrder = 1;
                a.collisionZone = {top:0,left:0,bottom:0,right:0};
                if (!e) {
                    a.div = document.createElement("div");
                    a.div.style.overflow = "hidden";
                    a.div.style.width = p;
                    a.div.style.height = j;
                    a.div.style.position = "absolute";
                    a.image.style.position = "absolute";
                    a.div.appendChild(a.image);
                    a.div.style.zIndex = a.zOrder;
                    n.appendChild(a.div)
                }
                a.id = f.push(a) - 1;
                V.push(a);
                a.draw = function() {
                    if (e)try {
                        o.drawImage(a.image, a.initialWidth * a.actualAnimation, a.initialHeight * a.actualFrame, a.initialWidth, a.initialHeight, a.posX, a.posY, a.width, a.height)
                    } catch(b) {
                    }
                    if (a.frames > 0) {
                        if (a.animationInterval == a.animationSpeed && a.animationSpeed !== 0) {
                            if (a.actualFrame == a.frames)a.actualFrame = 0; else a.actualFrame++;
                            a.animationInterval = 0
                        }
                        a.animationSpeed !== 0 && a.animationInterval++;
                        if (!e) {
                            a.image.style.top = a.height * a.actualFrame * -1;
                            a.image.style.left = a.width * a.actualAnimation * -1
                        }
                    }
                };
                return{setPosition:function(b, k, m) {
                    a.posX = b;
                    a.posY = k;
                    a.zOrder = m || a.zOrder;
                    if (e)m && f.sort(function(B, N) {
                        return N.zOrder - B.zOrder
                    }); else {
                        a.div.style.left = b;
                        a.div.style.top = k;
                        a.div.style.zIndex = m || a.zOrder
                    }
                },setCollide:function(b) {
                    if (b && x.indexOf(a) == -1)x.push(a); else!b && x.indexOf(a) != -1 && x.remove(a)
                },onHit:function(b, k) {
                    a.hitEvents[b.id()] = k;
                    x.indexOf(a) == -1 && x.push(a)
                },setCollisionZone:function(b, k, m, B) {
                    a.collisionZone.left = B;
                    a.collisionZone.top = b;
                    a.collisionZone.right = k;
                    a.collisionZone.bottom = m
                },getCollisionZone:function() {
                    return a.collisionZone
                },clearHits:function() {
                    a.hitEvents = {}
                },switchSprite:function(b, k, m, B, N) {
                    a.image.src = b;
                    a.width = k;
                    a.height = m;
                    a.initialWidth = k;
                    a.initialHeight = m;
                    a.frames = B;
                    a.animations = N;
                    if (!e) {
                        a.image.style.width = k * (a.animations + 1);
                        a.image.style.height = m * (a.frames + 1);
                        a.div.style.width = k;
                        a.div.style.height = m
                    }
                    a.collisionZone = {top:0,left:0,bottom:0,right:0}
                },setAnimationSpeed:function(b) {
                    a.animationSpeed = b
                },setCurrentAnimation:function(b) {
                    a.actualAnimation = b
                },setCurrentFrame:function(b) {
                    a.actualFrame = b
                },resize:function(b, k) {
                    if (!e) {
                        a.div.style.width = b;
                        a.div.style.height = k;
                        a.image.style.width = b * (a.animations + 1);
                        a.image.style.height = k * (a.frames + 1)
                    }
                    a.width = b;
                    a.height = k
                },getAnimationSpeed:function() {
                    return a.animationSpeed
                },getCurrentAnimation:function() {
                    return a.actualAnimation
                },posX:function() {
                    return a.posX
                },posY:function() {
                    return a.posY
                },width:function() {
                    return a.width
                },height:function() {
                    return a.height
                },id:function() {
                    return a.id
                }}
            },tile:function(g, p, j) {
                var d = {};
                d.id = f.length;
                d.image = new Image;
                d.image.src = g;
                d.width = p;
                d.initialWidth = p;
                d.height = j;
                d.initialHeight = j;
                d.actualFrame = 0;
                d.posX = 0;
                d.posY = 0;
                d.zOrder = 1;
                if (!e) {
                    d.div = document.createElement("div");
                    d.div.style.overflow = "hidden";
                    d.div.style.width = p;
                    d.div.style.height = j;
                    d.div.style.position = "absolute";
                    d.image.style.position = "absolute";
                    d.div.appendChild(d.image);
                    d.div.style.zIndex = d.zOrder;
                    n.appendChild(d.div)
                }
                d.id = f.push(d);
                d.draw = function() {
                    if (e)try {
                        o.drawImage(d.image, 0, d.initialHeight * d.actualFrame, d.initialWidth, d.initialHeight, d.posX, d.posY, d.width, d.height)
                    } catch(s) {
                    } else d.image.style.top = d.height * d.actualFrame * -1
                };
                return{setPosition:function(s, a, b) {
                    d.posX = s;
                    d.posY = a;
                    d.zOrder = b || d.zOrder;
                    if (e)b && f.sort(function(k, m) {
                        return k.zOrder - m.zOrder
                    }); else {
                        d.div.style.left = s;
                        d.div.style.top = a;
                        d.div.style.zIndex = b || d.zOrder
                    }
                },resize:function(s, a) {
                    if (!e) {
                        d.div.style.width = s;
                        d.div.style.height = a;
                        d.image.style.width = s;
                        d.image.style.height = a * (d.frames + 1)
                    }
                    d.width = s;
                    d.height = a
                },posX:function() {
                    return d.posX
                }, posY:function() {
                    return d.posY
                },width:function() {
                    return d.width
                },height:function() {
                    return d.height
                },getActualFrame:function() {
                    return d.actualFrame
                },setActualFrame:function(s) {
                    return d.actualFrame = parseInt(s, 10)
                },id:function() {
                    return d.id
                },switchSprite:function(s, a, b) {
                    d.image.src = s;
                    d.width = a;
                    d.height = b;
                    d.initialWidth = a;
                    d.initialHeight = b;
                    d.actualFrame = 0;
                    if (!e) {
                        d.div.style.width = a;
                        d.div.style.height = b
                    }
                }}
            },background:function(g, p, j, d, s, a) {
                var b = this;
                if (e) {
                    b.image = new Image;
                    b.image.src = g
                } else n.style.backgroundImage = "url(" + g + ")";
                b.speed = p || 3;
                var k = function(m) {
                    switch (m) {case "N":b.directionX = 0;b.directionY = -1;break;case "W":b.directionX = -1;b.directionY = 0;break;case "S":b.directionX = 0;b.directionY = 1;break;case "E":b.directionX = 1;b.directionY = 0;break;default:b.directionX = 0;b.directionY = 0
                    }
                };
                k(j);
                b.posX = d || 0;
                b.posY = s || 0;
                b.zOrder = a || 0;
                b.id = f.push(b);
                b.moving = 0;
                b.draw = function() {
                    b.posX += b.speed * b.directionX * b.moving;
                    b.posY += b.speed * b.directionY * b.moving;
                    if (e) {
                        try {
                            o.drawImage(b.image, b.posX, b.posY);
                            o.drawImage(b.image, b.posX + b.image.width * b.directionX, b.posY + b.image.height * b.directionY);
                            o.drawImage(b.image, b.posX - b.image.width * b.directionX, b.posY - b.image.height * b.directionY)
                        } catch(m) {
                        }
                        if (b.directionX === -1) {
                            if (b.posX < b.image.width * -1)b.posX = 0
                        } else if (b.directionX === 1) {
                            if (b.posX > b.image.width)b.posX = 0
                        } else if (b.directionY === -1) {
                            if (b.posY < b.image.height * -1)b.posY = 0
                        } else if (b.directionY === 1)if (b.posY > b.image.height)b.posY = 0
                    } else n.style.backgroundPosition = b.posX + "px " + b.posY + "px"
                };
                return{start:function() {
                    b.moving = 1
                },stop:function() {
                    b.moving = 0
                },setDirection:function(m) {
                    b.posX = b.posY = 0;
                    k(m)
                },setSpeed:function(m) {
                    b.speed = m
                }}
            },addLoop:function(g) {
                G.push(g)
            }}
        }(600, 600);
        t.detectCanvas();
        t.init();
        t.setMaxFps(40);
        t.enableCollisions();
        var R = function(c, i) {
            var q = i.posX,e = c.posX,f = c.posY,v = c.conf.width,n = c.conf.height,o = ~~(v / 2) + e,D = Math.floor(1.5),w = 14;
            if (o - q < q + i.conf.width - o)w *= -1;
            if (f + n + 3 > 600)D = 0;
            if (w < 0 && e + w < 0 || w > 0 && e + v + w > 600)w = 0;
            c.setPosition(e + w, f + D)
        },h = new F(StructuresWithShadow.playerConf, 260, 400);
        h.sides = 0;
        h.updown = 0;
        h.shoot = 0;
        var A = new F(StructuresWithShadow.spearConf, -100, -100),Z = function(c) {
            switch (c.keyCode) {case 80:if (PAUSED) {
                t.start();
                PAUSED = 0
            } else {
                t.stop();
                PAUSED = 1
            }break;case 38:h.updown = -1;break;case 40:h.updown = 1;break;case 37:h.sides = -1;break;case 39:h.sides = 1;break;case 90:if (h.shoot == 0) {
                h.shoot = 1;
                A.setPosition(h.posX + 50, h.posY - 10)
            }
            }
            c.stopPropagation()
        },$ = function(c) {
            switch (c.keyCode) {case 38:if (h.updown === -1)h.updown = 0;break;case 40:if (h.updown === 1)h.updown = 0;break;case 37:if (h.sides === -1)h.sides = 0;break;case 39:if (h.sides === 1)h.sides = 0
            }
        };
        if (document.addEventListener) {
            document.addEventListener("keydown", Z, false);
            document.addEventListener("keyup", $, false)
        } else if (document.attachEvent) {
            document.attachEvent("onkeydown", Z);
            document.attachEvent("onkeyup", $)
        }
        t.addLoop(function() {
            if (A.posY < 0) {
                h.shoot = 0;
                A.setPosition(-200, -200)
            }
            h.shoot && A.setPosition(A.posX, A.posY - 20)
        });
        t.addLoop(function() {
            var c = h.posX + h.sides * 7,i = h.posY + h.updown * 7;
            c >= 0 && c <= 600 - h.conf.width && i > 0 && i < 600 - h.conf.height && h.setPosition(c, i)
        });
        (new t.background("images/backgrounds/" + LEVELS[z].background, 3, "S")).start();
        for (var l = LEVELS[z].nrOfObstacles; l--;)S();
        t.addLoop(function() {
            for (var c = u.length; c--;)u[c].posY > 600 ? S(c) : u[c].setPosition(u[c].posX, u[c].posY + 3)
        });
        for (l = LEVELS[z].nrOfEnemies; l--;)J();
        t.addLoop(function() {
            for (var c = r.length; c--;)r[c].posY > 600 ? J(c) : r[c].setPosition(r[c].posX, r[c].posY + r[c].conf.speed)
        });
        var y = document.createElement("img");
        y.style.position = "absolute";
        y.style.top = "0";
        y.style.left = "0";
        y.style.cursor = "pointer";
        y.style.zIndex = Z_GUI * 2;
        y.src = "images/boards/" + LEVELS[z].board;
        y.onclick = function() {
            y.style.display = "none";
            t.start();
            PAUSED = 0;
            T(C)
        };
        document.body.appendChild(y);
        var O = [],P = 5,Q = [];
        for (l = 0; l < 5; l++) {
            O[l] = new t.tile("images/hp.png", 30, 30);
            O[l].setPosition(5 + 32 * l, 5, Z_GUI)
        }
        for (l = 0; l < 5; l++) {
            Q[l] = new t.tile("images/interface/all.png", 31, 41);
            Q[l].setPosition(600 - 32 * l - 35, 555, Z_GUI)
        }
        var T = function(c) {
            c = c + "";
            var i = c.length;
            for (l = 0; l < 5 - i; l++)c = "0" + c;
            i = c.length;
            for (l = 0; l < i; l++)Q[4 - l].setActualFrame(c.charAt(l))
        }, aa = function() {
            I -= 10;
            if (P > 1) {
                P--;
                O[P].setActualFrame(1)
            } else {
                var c = window.location.href.split("/");
                c.pop();
                c.push("lose.html");
                window.location = c.join("/")
            }
        }
    })();